package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.qf.entity.Stu;
import com.qf.service.StuService;
import com.qf.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * --- 年少有为 ---
 *
 * @author ChenZhuo
 * @date 2025/8/12
 * @desc
 */
@RestController
@Api(tags = "关于stu表的增删改查")
public class StuController {
    @Autowired
    private StuService stuService;

    @GetMapping("/stu/find")
    @ApiOperation("根据id查询数据")
    public R findById(int id){
        Stu stu=stuService.findById(id);
        return R.success(stu);
    }
    @GetMapping("/stu/findAll")
    @ApiOperation("查询stu表所有数据")
    public R findAll(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Stu> stus=stuService.findAll();
        return R.success(stus);
    }
    @GetMapping("/stu/findByLike")
    @ApiOperation("模糊查询stu表数据")
    public R findByLike(@RequestParam HashMap<String,String> map,int pageNum, int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Stu> stus=stuService.findByLike(map);
        return R.success(stus);
    }
    @GetMapping("/stu/add")
    @ApiOperation("往stu表添加数据")
    public R addStu(Stu stu){
        boolean result=stuService.addStu(stu);
        return R.success(result);
    }
    @GetMapping("/stu/update")
    @ApiOperation("修改stu表数据")
    public R updateStu(Stu stu){
        boolean result=stuService.updateStu(stu);
        return R.success(result);
    }
    @PostMapping("/stu/delete")
    @ApiOperation("根据id删除stu表数据")
    public R deleteStu(int id){
        boolean result=stuService.deleteStu(id);
        return R.success(result);
    }
    @PostMapping("/stu/deleteSome")
    @ApiOperation("根据id批量删除stu表数据")
    public R deleteSomeStu(@RequestParam List<Integer> id){
        boolean result=stuService.deleteSomeStu(id);
        return R.success(result);
    }
    @PostMapping("/stu/addSome")
    @ApiOperation("批量增加stu表数据")
    public R addSomeStu(@RequestBody List<Stu> stus){
        boolean result=stuService.addSomeStu(stus);
        return R.success(result);
    }
}
